<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            background-color: #000000;
        }
        
        .box {
            left: 300px;
            top: 50px;
            width: 400px;
            height: 300px;
            position: relative;
            box-sizing: border-box;
        }
        
        .box img {
            width: 100%;
            height: 100%;
        }
        
        .box:active,
        .box:visited {
            animation-name: flip;
            animation-duration: 1200ms;
            animation-timing-function: linear;
            opacity: 1;
        }
        
        @keyframes flip {
            30% {
                transform: perspective(400px) rotate3d(0, 1, 0, 60deg);
                animation-timing-function: ease-in;
                /*缓动函数*/
            }
            60% {
                transform: perspective(400px) rotate3d(0, 1, 0, 120deg);
                animation-timing-function: ease-in;
                /*缓动函数*/
                opacity: 1;
            }
            100% {
                transform: perspective(400px) rotate3d(0, 1, 0, 180deg);
                animation-timing-function: ease-in;
                /*缓动函数*/
            }
        }
    </style>
</head>

<body>
    <div class="box">
        <img id="img" src="img/1.jpg" />
    </div>
    <script>
        var img = document.getElementById("img");
        console.log(img);
        img.addEventListener("click", function(e) {
            var imageName = img.src;
            var arr = imageName.split(".");
            var indexArr = arr[arr.length - 2].split("/");
            var index = indexArr[indexArr.length - 1];
            index++;
            if (index > 3) {
                index = 1;
            }
            img.src = "img/" + index + ".jpg";
        })
    </script>
</body>

</html>